package com.uha.reggie.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author uha
 * @date 2023/6/12
 * @apiNote
 */
@MapperScan("com.uha.reggie.mapper")
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {

    //注册乐观锁插件  拦截器

    //@Bean
    //public OptimisticLockerInterceptor optimisticLockerInterceptor(){
    //    return new OptimisticLockerInterceptor();
    //}


    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();

        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return mybatisPlusInterceptor;
    }

    //逻辑删除组件

    //@Bean
    //public ISqlInjector sqlInjector(){
    //    return new LogicSqlInjector();
    //}

    //SQL执行效率插件

    //@Bean
    //@Profile({"dev","test"})
    //public PerformanceInterceptor performanceInterceptor(){
    //    return new PerformanceInterceptor();
    //}

}
